using Dotnet.Script.ScriptPath;

namespace Dotnet.Script.Project;


class Project
{

    public static async Task BackupCodeProject()
    {
        List<string> filePaths = await PathHandle.GetFilesAsync();
        List<Task> tasks = new List<Task>();
        foreach (var filePath in filePaths)
        {
            tasks.Add(Task.Run(() => CopyFileToDstDirPath(filePath)));
        }
        await Task.WhenAll(tasks);
    }


    private static void CopyFileToDstDirPath(string filePath)
    {
        var newFilePath = PathHandle.GetNewFilePath(filePath);
        var newFolderPath =
            Path.GetDirectoryName(newFilePath) ?? throw new Exception("newFolderPath is null");
        if (!Directory.Exists(newFolderPath))
            Directory.CreateDirectory(newFolderPath);
        File.Copy(filePath, newFilePath, true);
    }

}
